<?
class adminController extends iMVC_Controller{


    public function index(){





    }
    public function loginForm(){
    
        $this->template_dir='admin/view/';
        $this->display("admin-login.tpl"); 
    
    }
    public function user(){
    
            $this->template_dir='admin/view/';
            $this->checkLogin();
            $user=new userModel();
            $rs=$user->fetchAll();
            $table=new iMVC_View_Table();
            $table->addCol('action',new Amxx_View_Table_User_Action($this->getBaseUrl(),"user/del?id=","user/forbit?id="),100);
            $table->addCol('封ip',new iMVC_View_Table_Col_Action('封ip',$this->getBaseUrl().'user/forbitIp','user_id'),98);
            $table->generateTable($rs);
            $this->assign('table',$table);
            $this->display("admin.tpl"); 
    
    
    
    }
    public function info(){

        $this->template_dir='admin/view/';


        $this->checkLogin();
        $tm=new infoModel();
        $table=new iMVC_View_Table();
        //添加时列名不能为数字，为数字时array_merge会破坏键值
        $table->addCol('预览',new Amxx_View_Table_Info_Preview('预览',$this->getBaseUrl()."info/single","info_id"),0);
        $table->addCol('删除',new iMVC_View_Table_Col_Action('删除',$this->getBaseUrl()."info/delInfo","info_id"),-1);
        $table->addCol('相册',new iMVC_View_Table_Col_Action('上传照片',$this->getBaseUrl()."info/uploadPhoto","info_id"),-2);
        //$table->setCol('info_ico',new Amxx_View_Table_Pic_Action(),11);
        //$table->setCol('info_pic',new Amxx_View_Table_Pic_Action(),11);
        $table->hideCol('info_google_address');
        $table->hideCol('info_city');
        $table->hideCol('info_area');
        $table->hideCol('info_tel');
        $table->hideCol('info_price');
        $table->hideCol('info_address');
        $table->hideCol('info_price');
        $table->hideCol('info_opentime');
        $table->hideCol('info_cap');
        $table->hideCol('info_detail');
        $table->hideCol('info_pic');
        $table->hideCol('info_ico');
        $table->generateTable($tm->fetchAll());
        $this->assign('table',$table);
        $this->display("admin.tpl"); 

    }
    public function ads(){

        $this->template_dir='admin/view/';
        $this->checkLogin();
        $ads=new adsModel();
        $adsRs=$ads->fetchAll();
        $adsTable=new iMVC_View_Table();
        $adsTable->setCol('ads_pic',new Amxx_View_Table_Pic_Action(),11);
        $adsTable->setCol('预览',new iMVC_View_Table_Col_Action('预览',$this->getBaseUrl()."ads/single","ads_id"));
        $adsTable->generateTable($adsRs);
        $this->assign('table',$adsTable);       
        $this->display("admin.tpl"); 


    }
    public function slider(){
    
        $this->template_dir='admin/view/';
        $this->checkLogin();
        $slider=new sliderModel();
        $adsRs=$slider->fetchAll();
        $adsTable=new iMVC_View_Table();
        $adsTable->addCol('删除',new iMVC_View_Table_Col_Action('删除',$this->getBaseUrl()."slider/del","slider_id"),10);
        $adsTable->generateTable($adsRs);
        $this->assign('table',$adsTable);       
        $str="<p>你可以<a href=".$this->getBaseUrl()."slider/upForm >添加</a>滚动图片</p>";
        $this->assign('addSlider',$str);       
        $this->display("admin.tpl"); 

    }

    public function addNoticeForm(){
    
       
        $this->template_dir='admin/view/';

        $this->checkLogin();
        $this->display("admin-addNotice.tpl"); 
    
    
    }
    public function notice(){
        $this->template_dir='admin/view/';
        $this->checkLogin();
        $notice=new noticeModel();
        $noticeRs=$notice->fetchAll();
        $noticeTable=new iMVC_View_Table();
        $noticeTable->addCol('删除',new iMVC_View_Table_Col_Action('删除',$this->getBaseUrl()."notice/del","notice_id"),10);
        $noticeTable->hideCol('notice_content');
        $noticeTable->generateTable($noticeRs);
        $this->assign('table',$noticeTable);       
        $str="<p>你可以<a href=".$this->getBaseUrl()."admin/addNoticeForm>添加</a>通知</p>";
        $this->assign('addSlider',$str);       
        $this->display("admin.tpl"); 
    }
    public function addNotice(){
    
    
    
    
    }

    public function loginCheck(){

        $this->setModelDir('admin/model');
        session_start();
        $name=$_POST["name"];
        $pass=$_POST["pass"];
        $user=new adminModel();
        if($user->checkPass($name,$pass)){

                $ip=$_SERVER["REMOTE_ADDR"];
                $_SESSION['admin']=$user;
                //header("Location:".$this->getBaseUrl()."user/center");
                header("Location:".$this->getBaseUrl()."admin/user");
            
        }
        else{
                $this->assign("isSuc",false);
                //$this->assign("tip","登录失败，请检查用户名和密码!");
                echo "登录失败";
        }
        //>>>
    }

    //重写父类的before函数,在controller执行前可做验证
    protected function before(){

        
    
    }
    protected function checkLogin(){

        $this->setModelDir('admin/model');
        session_start();
        if(empty($_SESSION['admin'])){

            header("Location:".$this->getBaseUrl()."admin/loginForm");

        }
    }
    public function loginOut(){

        $this->checkLogin();
        unset($_SESSION['admin']);
        header("Location:".$this->getBaseUrl()."admin/loginForm");
    }



    public function regRuleForm(){
    
        $id=$_GET["ln"]; 
        if(empty($id)){
            $id=1;
        }
        $this->template_dir='admin/view/';
        $this->checkLogin();
        $sf=new siteinfoModel();
        $sf->findByPk($id);
        $r=$sf->content;
        $this->assign("content",$r);
        $this->assign("ln",$id);
        $this->display("admin-regRule.tpl"); 
    
    }

    public function regRule(){

        $regRule=$_POST['regRule'];
        $sf=new siteinfoModel();
        var_dump($sf->properties[$sf->_pk]);
        $sf->siteinfo_id=1;
        $sf->content=$regRule;
        $sf->save();
        //echo "<script>alert('添加成功');history.go(-1);</script>";
    }

}

// vim600:ts=4 st=4 foldmethod=marker foldmarker=<<<,>>>
// vim600:syn=php commentstring=//%s
